package com.apes.hr.salary.rewardPunish.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.frame.model.Branch;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.*;

/**
 * 功能：集体奖惩记录单明细
 * @author linwz
 * @create 2019-02-27 09:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = TeamRewardPunishItem.CONST_TABLE_NAME)
public class TeamRewardPunishItem extends Model {
    public static final String CONST_TABLE_NAME = "hr_team_reward_punish_Item";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "集体奖惩记录明细")
    @Comment("奖惩明细内码")
    private long id;   //奖惩明细内码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "work_branch_id", referencedColumnName = "id")
    @Comment("工作部门")
    private Branch workBranch;   //工作部门

    @Column(name = "item_amt", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("奖励总额")
    private double itemAmt = 0;    //奖励总额

    @Column(name = "item_punish_amt", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("处罚总额")
    private double itemPunishAmt = 0;    //处罚总额

    @Column(name = "no_punish", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("免罚总额")
    private double noPunish = 0;//免罚总额

    @Column(name = "distribution", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否已分配")
    private boolean distribution; //是否已分配

    @Column(name = "distribution_date")
    @Comment("分配日期")
    private Date distributionDate; //分配日期

    @ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    @JoinColumn(name = "Team_reward_punish_id", referencedColumnName = "id")
    @Comment("集体奖惩记录单号")
    private TeamRewardPunish teamRewardPunish; //集体奖惩记录单号

//    @OneToMany(mappedBy = "teamRewardPunishItem",fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
//    private Set<TeamRewardPunishDistribution> teamRewardPunishDistributions = new HashSet(); //集体奖惩分配
//
//    public Set<TeamRewardPunishDistribution> getTeamRewardPunishDistributions() {
//        if (teamRewardPunishDistributions==null||teamRewardPunishDistributions.isEmpty())return new HashSet<>();
//        for (TeamRewardPunishDistribution item : teamRewardPunishDistributions) {
//            item.setTeamRewardPunishItem(this);
//        }
//        return teamRewardPunishDistributions;
//    }
//
//    public void setTeamRewardPunishDistributions(Set<TeamRewardPunishDistribution> teamRewardPunishDistributionSet) {
//        if (teamRewardPunishDistributionSet == null) teamRewardPunishDistributionSet = new HashSet();
//        this.teamRewardPunishDistributions.clear();
//        this.teamRewardPunishDistributions.addAll(teamRewardPunishDistributionSet);
//    }

    @Column(name = "state", length = 10)
    @Comment("状态")
    private String state; //状态： ('sent', '提交'), ('done', '已审核')

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "approve_uid", referencedColumnName = "id")
    @Comment("审批人")
    private PartyRole approveUid; //审批人

    @Column(name = "approve_date")
    @Comment("审批日期")
    private Date approveDate; //审批日期

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "submit_uid", referencedColumnName = "id")
    @Comment("发文人")
    private PartyRole submitUid; //提交人

    @Column(name = "submit_date")
    @Comment("发文日期")
    private Date submitDate; //提交日期



}
